<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { propApi } from '@/api/controller';
  import { ToastSuccess, ToastWarning, Toastloading } from '@/utils/public';
  import { ElMessageBox } from 'element-plus';
  import whiteForm from './whiteForm.vue';
  const whiteFormRef = ref()
  const action = reactive({
    list:[] as any[],
  })
  const options = [
    {type:0,label:'否'},
    {type:1,label:'是'}
  ]
  const listQuery = reactive({
    user_id:'',
    uuid:'',
    status:-1,
  })
  const handleSerach = () => {
    getList();
  };
  const handleDel = (row:any = {})=>{
    const { nickname='', id=0 } = row
    ElMessageBox.confirm(`确定删除用户：${nickname}白名单吗?`, "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
    .then(async () => {
      const loading = Toastloading();
      await propApi.luckGiftDelWhite({
        white_id:id,
      });
      loading.close();
      ToastSuccess('删除成功');
      getList();
    })
    .catch(() => {});
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await propApi.luckGiftWhiteList(listQuery)
    loading.close()
    const { data=[] } = res
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <el-input v-model="listQuery.uuid" placeholder="请输入用户UUID"/>
        </div>
        <div class="labelItem">
          <div class="label">用户ID：</div>
          <el-input v-model="listQuery.user_id" placeholder="请输入用户ID"/>
        </div>
        <div class="labelItem">
          <div class="label">是否发放：</div>
          <el-select v-model="listQuery.status" placeholder="请选择礼物池状态">
            <el-option label="全部状态" :value="-1"/>
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item.label"
              :value="item.type"
            />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">搜索</el-button>
          <el-button type="primary" @click="whiteFormRef.openDialog()">新增白名单</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border
    >
      <el-table-column width="100" prop="id" label="白名单ID" />
      <el-table-column min-width="80" prop="user_id" label="用户ID" />
      <el-table-column min-width="80" prop="uuid" label="用户UUID" />
      <el-table-column min-width="120" show-overflow-tooltip prop="nickname" label="用户昵称" />
      <el-table-column min-width="80" prop="diamond_num" label="钻石数" />
      <el-table-column min-width="80" prop="status" label="是否发放">
        <template #default="scoped">
          {{ options.find(res=>res.type == scoped.row.status)?.label || scoped.row.status }}
        </template>
      </el-table-column>
      <el-table-column width="120" fixed="right" label="操作">
        <template #default="scoped">
          <el-button type="danger" @click="handleDel(scoped.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <whiteForm ref="whiteFormRef" @update-list="getList" />
  </div>
</template>
